package com.xinyue.exceltool.logic.convert.impl;

import com.xinyue.exceltool.logic.convert.ICellValueTypeStrategy;
import com.xinyue.exceltool.logic.convert.ValueConvertUtil;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author 王广帅
 * @Date 2021/5/9 0:09
 */
public class FloatArrayConvert implements ICellValueTypeStrategy {
    @Override
    public Object convert(String value) {
        if (StringUtils.isEmpty(value)) {
            return null;
        }
        String tempValue = ValueConvertUtil.replaceChineseComma(value);
        String[] strValue = ValueConvertUtil.splitByComma(tempValue);
        List<Float> array = Arrays.stream(strValue).filter(c -> !StringUtils.isEmpty(c)).map(c -> Float.parseFloat(c)).collect(Collectors.toList());
        return array;
    }
}
